package com.sporadic.backstage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sporadic.backstage.entity.DishesCombo;
import com.sporadic.backstage.service.DishesComboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin(origins = {"http://localhost:8080"}, methods = {RequestMethod.GET, RequestMethod.POST}, allowCredentials = "true")
@Controller
public class DishesComboController {
    //test
    @Autowired
    private DishesComboService dishescomboService;


    /**
     * 分页查询套餐信息
     * @param map 分页条件
     * @return 返回分页信息
     */
    @RequestMapping("/queryDishesCombo")
    @ResponseBody
    public IPage<DishesCombo> queryDishesCombo(@RequestBody Map<String,Object> map){
        System.out.println(map);
        Page<DishesCombo> page = new Page<>();
        page.setCurrent((Integer)map.get("current"));
        page.setSize((Integer)map.get("pageSize"));
        return dishescomboService.queryDishesCombo(page,map);
    }

    /**
     * 批量删除套餐
     * @param list 套餐ID集合
     * @return 返回删除结果
     */
    @RequestMapping("/delDishesCombo")
    @ResponseBody
    public int delDishesCombo(@RequestParam("list") List list){
        return  dishescomboService.delDishesCombo(list);
    }


    /**
     * 批量下架
     * @param list 套餐ID集合
     * @return 返回下架修改的结果
     */
    @RequestMapping("/modifyDishesComboStatus")
    @ResponseBody
    public int modifyDishesComboStatus(@RequestParam("list") List list){
        return dishescomboService.modifyDishesComboStatus(list);
    }

    /**
     * 添加套餐信息
     * @param dishesCombo 套餐信息
     * @return 添加结果
     */
    @RequestMapping("/insertDishesCombo")
    @ResponseBody
    public int insertDishesCombo(DishesCombo dishesCombo){
        return  dishescomboService.insertDishesCombo(dishesCombo);
    }


}
